package directorywatcher;

import com.darylteo.nio.DirectoryChangedSubscriber;
import com.darylteo.nio.DirectoryWatcher;
import com.darylteo.nio.ThreadPoolDirectoryWatchService;
import java.nio.file.Path;

public class Example {

    public static void main(String[] args) throws Exception {
        // Get Watcher
        ThreadPoolDirectoryWatchService factory = new ThreadPoolDirectoryWatchService(); // or PollingDirectoryWatchService
        DirectoryWatcher watcher = factory.newWatcher("/Users/dingjianfeng/Work/gitlab/es_proxy/config/push/");

        watcher.exclude("*.swp");
        // Subscribe
        watcher.subscribe(new DirectoryChangedSubscriber() {
            public void directoryChanged(DirectoryWatcher watcher, Path path) {
                System.out.println("Something changed! " + path.toString());
            }
        });

        System.out.println("-------");
        System.in.read();
        // Cleanup
        factory.close();
    }
}